//
//  UIImage+Extension.swift
//  SFWeiboPro
//
//  Created by happy on 2017/9/22.
//  Copyright © 2017年 happy. All rights reserved.
//

import UIKit

extension UIImage {
    
    //给图片设置圆角
    func setupCycleImage(size: CGSize, backColor: UIColor = UIColor.white, lineColor: UIColor = UIColor.darkGray) -> UIImage? {
        
        let rect = CGRect(origin: CGPoint(), size: size)
        
        //获取上下文
        UIGraphicsBeginImageContextWithOptions(rect.size, true, 0)
        
        //设置填充色
        backColor.setFill()
        UIRectFill(rect)
        
        //根据路径画圆
        let path = UIBezierPath(ovalIn: rect)
        path.addClip()
        
        //绘图,在区域内拉伸图片
        draw(in: rect)
        
        //绘制切面圆
        lineColor.setStroke()
        path.lineWidth = 2.0
        path.stroke()
        
        let result = UIGraphicsGetImageFromCurrentImageContext()
        
        UIGraphicsEndImageContext()
        
        return result
    }

    
}
